home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Container / Sources / View.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  11.8 KB  |  413 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                View.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef VIEW_H
  13. #include "View.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef DEFINES_K
  21. #include "Defines.k"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. #ifndef FRAME_H
  29. #include "Frame.h"
  30. #endif
  31.  
  32. #ifndef SELECT_H
  33. #include "Select.h"
  34. #endif
  35.  
  36. #ifndef COMMANDS_H
  37. #include "Commands.h"
  38. #endif
  39.  
  40. #ifndef PROXY_H
  41. #include "Proxy.h"
  42. #endif
  43.  
  44. // ----- Framework Layer -----
  45.  
  46. #ifndef FWUTIL_H
  47. #include "FWUtil.h"
  48. #endif
  49.  
  50. #ifndef FWEVEDEF_H
  51. #include "FWEveDef.h"
  52. #endif
  53.  
  54. #ifndef FWPRESEN_H
  55. #include "FWPresen.h"
  56. #endif
  57.  
  58. #ifndef FWSCROLR_H
  59. #include "FWScrolr.h"
  60. #endif
  61.  
  62. #ifndef FWSCLBAR_H
  63. #include "FWSclBar.h"
  64. #endif
  65.  
  66. #ifndef FWGROWBX_H
  67. #include "FWGrowBx.h"
  68. #endif
  69.  
  70. #ifndef FWCONTXT_H
  71. #include "FWContxt.h"
  72. #endif
  73.  
  74. #ifndef FWCLPCMD_H
  75. #include "FWClpCmd.h"
  76. #endif
  77.  
  78. #ifndef FWFCTCLP_H
  79. #include "FWFctClp.h"
  80. #endif
  81.  
  82. // ----- OS Layer -----
  83.  
  84. #ifndef FWMENU_H
  85. #include "FWMenu.h"
  86. #endif
  87.  
  88. #ifndef FWRECSHP_H
  89. #include "FWRecShp.h"
  90. #endif
  91.  
  92. #ifndef FWCURSOR_H
  93. #include "FWCursor.h"
  94. #endif
  95.  
  96. #ifndef FWEVENT_H
  97. #include "FWEvent.h"
  98. #endif
  99.  
  100. #ifndef FWODGEOM_H
  101. #include "FWODGeom.h"
  102. #endif
  103.  
  104. // ----- OpenDoc Includes -----
  105.  
  106. #ifndef SOM_Module_OpenDoc_Commands_defined
  107. #include <CmdDefs.xh>
  108. #endif
  109.  
  110. #ifndef SOM_Module_OpenDoc_StdProps_defined
  111. #include <StdProps.xh>
  112. #endif
  113.  
  114. //========================================================================================
  115. // Runtime Information
  116. //========================================================================================
  117.  
  118. #ifdef FW_BUILD_MAC
  119. #pragma segment odfcontainer
  120. #endif
  121.  
  122. //========================================================================================
  123. // CContainerView
  124. //========================================================================================
  125.  
  126. FW_DEFINE_CLASS_M1(CContainerView, FW_CSuperView)
  127.  
  128. // IMPORTANT: the constant below must match the resource label for RContainerView in views.fr
  129. const FW_ClassTypeConstant LContainerView = FW_TYPE_CONSTANT('c','t','v','w');
  130. FW_REGISTER_ARCHIVABLE_CLASS(LContainerView, CContainerView, CContainerView::Create, FW_CView::Read, CContainerView::Destroy, FW_CView::Write)
  131.  
  132. //----------------------------------------------------------------------------------------
  133. // CContainerView::CContainerView
  134. //----------------------------------------------------------------------------------------
  135.  
  136. CContainerView::CContainerView(Environment* ev, CContainerFrame* frame, FW_CRect& bounds, 
  137.                                     FW_CPoint& extent, CContainerPart* part) :
  138.     FW_CSuperView(ev, frame, bounds, kContainerViewID, extent, FW_kXYScrolling),
  139.     fContainerPart(part),
  140.     fContainerFrame(frame),
  141.     fPartContent(part->GetPartContent())
  142. {    
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. // CContainerView::CContainerView
  147. //----------------------------------------------------------------------------------------
  148.  
  149. CContainerView::CContainerView(Environment* ev) :
  150.     FW_CSuperView(ev),
  151.     fContainerPart(NULL),
  152.     fContainerFrame(NULL),
  153.     fPartContent(NULL)
  154. {    
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. // CContainerView::~CContainerView
  159. //----------------------------------------------------------------------------------------
  160.  
  161. CContainerView::~CContainerView()
  162. {
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. // CContainerView::Draw
  167. //----------------------------------------------------------------------------------------
  168.  
  169. void CContainerView::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  170. {
  171.     // Render inside the content view
  172.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  173.     FW_CRect invalidRect;
  174.     vc.GetClipRect(invalidRect);
  175.  
  176.     FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, fContainerPart->GetBackgroundColor());
  177.  
  178.  
  179.     // ----- Render every proxy -----
  180.     //    Note: like ODFDraw I don't let OpenDoc draws embedded facets because I want to
  181.     //    manage z-ordering myself
  182.     CContentProxyIterator ite(fPartContent);
  183.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  184.     {
  185.         FW_CRect updateBox = proxy->GetBounds(ev);
  186.         if (invalidRect.IsIntersecting(updateBox))
  187.             proxy->Render(ev, odFacet, vc);
  188.     }
  189.  
  190.     // ----- Render selection handles -----
  191.     // Do not render handles for print / print preview
  192.     if (fContainerFrame->GetWindow(ev)->IsActive(ev) && fContainerFrame->HasSelectionFocus(ev) && odFacet->GetCanvas(ev)->IsDynamic(ev))    
  193.     {    
  194.         fContainerFrame->GetSelection()->RenderSelectionHandles(ev, vc, fContainerFrame->GetZoomFactor());
  195.     }
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. // CContainerView::AdjustToNewLayout
  200. //----------------------------------------------------------------------------------------
  201.  
  202. void CContainerView::AdjustToNewLayout(Environment *ev, 
  203.                                     const FW_CPoint& oldExtent, 
  204.                                     const FW_CPoint& newExtent, 
  205.                                     FW_ERedrawVerb redraw)
  206. {
  207. FW_UNUSED(oldExtent);
  208. FW_UNUSED(newExtent);
  209.  
  210.     fContainerFrame->AdjustContentViewSize(ev, redraw);
  211. }
  212.     
  213. //----------------------------------------------------------------------------------------
  214. // CContainerView::AdjustCursor
  215. //----------------------------------------------------------------------------------------
  216.  
  217. FW_Handled CContainerView::AdjustCursor(Environment* ev, ODFacet* facet, const FW_CPoint& where, ODEventInfo* eventInfo)
  218. {
  219.     if (fContainerFrame->GetWindow(ev)->IsActive(ev) == false)
  220.     {
  221.         // Keep the arrow cursor in non-active windows
  222.         FW_gArrowCursor.Select();
  223.     }
  224.     // Must call the base class first to adjust cursor in active border of embedded frames
  225.     else if (FW_CView::AdjustCursor(ev, facet, where, eventInfo) == false)
  226.     {
  227.         // convert mouse position to content space for WhichProxy
  228.         FW_CPoint mouse(where);
  229.         FrameToViewContent(ev, mouse);
  230.         FW_CViewContext vc(ev, this, facet); 
  231.  
  232.         // Check if mouse is over the selection's handle first
  233.         short proxyHandle;
  234.         CContainerSelection* selection = fContainerFrame->GetSelection();
  235.         
  236.         if (selection->WhichHandle(ev, vc, mouse, proxyHandle, fContainerFrame->GetZoomFactor()))
  237.         {
  238.             switch(proxyHandle)
  239.             {
  240.                 case kInTopLeftCorner:
  241.                 case kInBottomRightCorner:
  242.                     FW_gSizeNWSECursor.Select();
  243.                     break;
  244.                 case kInTopRightCorner:
  245.                 case kInBottomLeftCorner:
  246.                     FW_gSizeNESWCursor.Select();
  247.                     break;
  248.                 case kInTopMiddle:
  249.                 case kInBottomMiddle:
  250.                     FW_gSizeNSCursor.Select();
  251.                     break;
  252.                 case kInLeftMiddle:
  253.                 case kInRightMiddle:
  254.                     FW_gSizeWECursor.Select();
  255.                     break;
  256.             }
  257.         }
  258.         
  259.         // Else use the hand cursor over a proxy to show dragging operation
  260.         else if (fContainerPart->WhichProxy(ev, vc, mouse, TRUE))
  261.             FW_gOpenHandCursor.Select();
  262.  
  263.         // Else use the cross hair cursor to show selection operation
  264.         else
  265.             FW_gCrossHairCursor.Select();
  266.     }
  267.     return FW_kHandled;
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. //    CContainerView::DoVirtualKeyDown
  272. //----------------------------------------------------------------------------------------
  273.  
  274. FW_Handled CContainerView::DoVirtualKeyDown(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
  275. {    
  276.     FW_Handled wasHandled = FW_kNotHandled;
  277.     
  278.     switch (theVirtualKeyEvent.GetKeyCode(ev))
  279.     {
  280.         case FW_kVKBackspace:
  281.         case FW_kVKClear:
  282.             if (!fContainerFrame->GetSelection()->IsEmpty(ev))
  283.             {
  284.                 FW_CClipboardCommand* cmd =    GetFrame(ev)->NewClipboardCommand(ev, kODCommandClear);
  285.                 if (cmd)
  286.                 {
  287.                     cmd->Execute(ev);
  288.                     wasHandled = FW_kHandled;
  289.                 }
  290.             }
  291.             break;
  292.     }
  293.  
  294.     return wasHandled;
  295. }
  296.  
  297. //----------------------------------------------------------------------------------------
  298. // CContainerView::WantsToBeTarget
  299. //----------------------------------------------------------------------------------------
  300.  
  301. FW_Boolean CContainerView::WantsToBeTarget(Environment* ev)
  302. {
  303. FW_UNUSED(ev);
  304.     return TRUE;
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. // CContainerView::DoMouseDown
  309. //----------------------------------------------------------------------------------------
  310.  
  311. FW_Handled CContainerView::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  312. {
  313.     FW_Handled result = FW_kHandled;
  314.     
  315.     ODFacet* theFacet = theMouseEvent.GetFacet(ev);
  316.     CContainerSelection* selection = fContainerFrame->GetSelection();
  317.     
  318.     if (selection->IsMouseInDraggableItem(ev, fContainerFrame, theMouseEvent, FALSE))
  319.     {
  320.         FW_gClosedHandCursor.Select();
  321.         if (!fContainerFrame->Drag(ev, theMouseEvent))
  322.             result = FW_kNotHandled;
  323.     }
  324.     else if (!selection->Resize(ev, theMouseEvent))
  325.     {
  326.         selection->SelectWithRectangle(ev, theMouseEvent);
  327.     }
  328.                         
  329.     return result;
  330. }
  331.  
  332. //----------------------------------------------------------------------------------------
  333. // CContainerView::SizeChanged
  334. //----------------------------------------------------------------------------------------
  335. //    My content view size has changed so I need to clip my embedded facets. It's better to do it
  336. //    here than in CContainerFrame::FrameShapeChanged because my frame shape can be changing but
  337. //    my bounds may not.
  338.  
  339. void CContainerView::SizeChanged(Environment* ev, const FW_CPoint& oldSize)
  340. {
  341.     FW_CSuperView::SizeChanged(ev, oldSize);
  342.     
  343.     FW_CFacetClipper facetClipper;
  344.     facetClipper.Clip(ev, fContainerFrame, NULL);
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. //    CContainerView::Create
  349. //----------------------------------------------------------------------------------------
  350.  
  351. void* CContainerView::Create(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  352. {
  353. FW_UNUSED(stream);
  354. FW_UNUSED(type);
  355.     FW_SOMEnvironment ev;
  356.     
  357.     // Call minimal constructor.  Data fields will be initialized in InitializeFromStream
  358.     return new CContainerView(ev);
  359. }
  360.  
  361. //----------------------------------------------------------------------------------------
  362. //    CContainerView::Destroy
  363. //----------------------------------------------------------------------------------------
  364.  
  365. void CContainerView::Destroy(void* object, FW_ClassTypeConstant type)
  366. {
  367. FW_UNUSED(type);
  368.     CContainerView* self = (CContainerView*) object;
  369.     delete self;
  370. }
  371.  
  372. //----------------------------------------------------------------------------------------
  373. //    CContainerView::Flatten
  374. //----------------------------------------------------------------------------------------
  375. // This method is required to handle custom resource fields added to the base type
  376.  
  377. void CContainerView::Flatten(Environment* ev, FW_CWritableStream& archive) const
  378. {
  379.     FW_CSuperView::Flatten(ev, archive);
  380.     
  381.     // Container doesn't have any custom fields to stream out
  382. }
  383.  
  384.  
  385. //----------------------------------------------------------------------------------------
  386. //    CContainerView::InitializeFromStream
  387. //----------------------------------------------------------------------------------------
  388. // This method is required to handle custom resource fields added to the base type
  389. // and to initialize other class fields not initialized in the minimal ctor.
  390.  
  391. void CContainerView::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
  392. {
  393.     // Read-in the base resource first
  394.     FW_CSuperView::InitializeFromStream(ev, stream);
  395.     
  396.     // Get a pointer to the frame which was pre-registered
  397.     FW_OObjectRegistry*    registry = stream.GetRegistry();
  398.     FW_CFrame* frame = (FW_CFrame*) registry->LookupByID(ev, FW_kPreregisteredFrameObject);
  399.     FW_ASSERT(frame != NULL);
  400.     
  401.     // Set the fContainerFrame, fContainerPart & fPartContent fields
  402.     fContainerFrame = FW_DYNAMIC_CAST(CContainerFrame, frame);
  403.     FW_ASSERT(fContainerFrame != NULL);
  404.     
  405.     FW_CEmbeddingPart* part = fContainerFrame->GetPart(ev);
  406.     fContainerPart = FW_DYNAMIC_CAST(CContainerPart, part);
  407.     FW_ASSERT(fContainerPart != NULL);
  408.  
  409.     fPartContent = fContainerPart->GetPartContent();
  410.     FW_ASSERT(fPartContent != NULL);
  411. }
  412.  
  413.